﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CMS.Repository.Translator
{
    class TeacherTranslator
    {
        public static List<CMS.Model.Teacher> ToTeacherModeList(List<CMS.Repository.Teacher> teacher)//translator teacher entity framework to teacher
        {
            List<CMS.Model.Teacher> tea = new List<CMS.Model.Teacher>();

            foreach (var a in teacher)
            {
                CMS.Model.Teacher b = new CMS.Model.Teacher()
                {
                    TeacherId = a.TeacherId,
                    TeacherName = a.TeacherName,
                    TeacherGender = a.TeacherGender,
                    DepartmentId = a.DepartmentId,
                    Department = new CMS.Model.Department()
                    {
                        DepartmentId = a.DepartmentId,
                        DepartmentName = a.Department.DepartmentName,//嵌套定义模版带来的好处！！！！！！
                        Manager = a.Department.Manager,
                        Phone = a.Department.Phone,
                        Remark = a.Department.Remark
                    },

                };

                tea.Add(b);
            }

            return tea;
        }

        public static List<CMS.Repository.Teacher> ToTeacherEFList(List<CMS.Model.Teacher> teacher)
        {
            List<CMS.Repository.Teacher> tea = new List<CMS.Repository.Teacher>();

            foreach (var a in teacher)
            {
                Teacher b = new Teacher()
                {
                    TeacherId = a.TeacherId,
                    TeacherName = a.TeacherName,
                    TeacherGender = a.TeacherGender,
                    DepartmentId = a.DepartmentId,
                    Department = new CMS.Repository.Department()
                    {
                        DepartmentId = a.Department.DepartmentId == 0 ? 0 : a.Department.DepartmentId,
                        DepartmentName = a.Department.DepartmentName == null ? "" : a.Department.DepartmentName,
                        Manager = a.Department.Manager == null ? "" : a.Department.Manager,
                        Phone = a.Department.Phone == null ? "" : a.Department.Phone,
                        Remark = a.Department.Remark == null ? "" : a.Department.Remark
                    },

                };

                tea.Add(b);
            }
            return tea;

        }
    }
}
